﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using  coffeeshop.Models;
using System.Globalization;

namespace coffeeshop.Forms
{
    public partial class frmTransferWorkingtime : Form
    {
        private WorkTime theWorkingTime { get; set; }
        public Form MyParentForm { get; set; }
        public frmTransferWorkingtime(WorkTime workingtime)
       {
            InitializeComponent();
            theWorkingTime = workingtime;
            lstProduct.FullRowSelect = true;
            lstProduct.GridLines = true;
            lstProduct.View = System.Windows.Forms.View.Details;
            lstProduct.Columns.Add("Tên hàng", 180);
            lstProduct.Columns.Add("Đơn giá", 80);
            lstProduct.Columns.Add("Số lượng", 80);
            lstProduct.Columns.Add("Đơn vị", 60);
            lstProduct.Columns.Add("Thành tiền", 180);
            loadData();
        }

        private void loadData()
        {
            WorkTime _theWorkingTime = new WorkTime();
            DataTable dt = new DataTable();
            dt = _theWorkingTime.getSaleProductInWorkingTime(theWorkingTime.WorkTimeId);
            if (dt.Rows.Count > 0)
            { 
                DateTime _Date = DateTime.Parse(dt.Rows[0]["ForDate"].ToString());
                txtDate.Text = _Date.ToString("dd/MM/yyyy");
                txtUserId.Text = dt.Rows[0]["UserName"].ToString();
                txtWorkingTimeId.Text = dt.Rows[0]["WorkingTime"].ToString();
                double _dbTotal = double.Parse( dt.Rows[0]["Total"].ToString());
                txtIncome.Text = String.Format(CultureInfo.InvariantCulture,
                                 "{0:0,0}", _dbTotal);
                foreach (DataRow row in dt.Rows)
                {
                    ListViewItem item = new ListViewItem();
                    item.Text = (row["Name"].ToString());
                    item.SubItems.Add(row["Price"].ToString());
                    item.SubItems.Add(row["Quantity"].ToString());
                    item.SubItems.Add(row["UnitName"].ToString());
                    item.SubItems.Add(String.Format(CultureInfo.InvariantCulture,
                                 "{0:0,0}",double.Parse( row["TotalPrice"].ToString()) ));
                    lstProduct.Items.Add(item);
                }
            }
        }
    }
}
